//
//  PHJMainViewController.swift
//  新浪微博
//
//  Created by jie peng on 16/5/19.
//  Copyright © 2016年 jie peng. All rights reserved.
//

import UIKit

class PHJMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        
        let  mainTabbar = PHJMainTabbar()
        
        mainTabbar.plusBtn.addTarget(self, action: #selector(PHJMainViewController.plusBtnClick), forControlEvents: .TouchUpInside)
        //通过KVC给tabbar赋值
        setValue(mainTabbar, forKey: "tabBar")
        
        loadChildControllers()
    }
    func plusBtnClick(){
        print("我被点击了")
    }
   private func loadChildControllers(){
    
    loadChildController(PHJHomeViewController(), title: "首页", imageName: "tabbar_home")
    loadChildController(PHJMessageViewController(), title: "消息", imageName: "tabbar_message_center")
    loadChildController(PHJDiscoverViewController(), title: "发现", imageName: "tabbar_discover")
    loadChildController(PHJProfileViewController(), title: "我的", imageName: "tabbar_profile")
    
    }
    
    private func loadChildController(vc:UIViewController,title:String,imageName:String){
        
        vc.view.backgroundColor = UIColor.whiteColor()
        vc.title = title
        vc.tabBarItem.image = UIImage(named: imageName)
        vc.tabBarItem.selectedImage = UIImage(named: imageName + "_selected")?.imageWithRenderingMode(.AlwaysOriginal)
        vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName : UIColor.orangeColor()], forState: .Selected)
        //MARK:设置tabbar文字的位置
        vc.tabBarItem.titlePositionAdjustment = UIOffset(horizontal: 0, vertical: -3)
        let nav = PHJBaseNavViewController(rootViewController: vc)
        addChildViewController(nav)
        
    }
}
